/*
 * core.h
 */
#ifndef CORE_H
#define CORE_H

#include <string>
#include "../connection.h"
#include "../connectionclosedexception.h"

using namespace std;

namespace newsclient {

  class GUI; //forward declaration

  /*
   *The Data handling class in the news client
   */
  class Core{

  public:
    Core(const char*, const int);

    ~Core();

    /*
     * Sets the gui pointer in the core.
     */
    void setGui(GUI*);

    /*
     * Start the client.
     */
    void run();

    /*
     *Return known serverstate
     */
    int getState() const;

    /*
     *Make the gui print a list of commands.
     */
    void printCommands() const;

        void addNewsgroup(string name);

	void handleServerResponse(unsigned char expected_ans, void (Core::*f)());

        void deleteNewsgroup(string id);

        void listNewsgroups();

        void enterNewsgroup(string id);

        void leaveNewsgroup();

        void addArticle(string author, string title);

        void deleteArticle(string id);

        void listArticles();

        void getArticle(string id);

		void printNameList();

		void printArticle();

		void matchWithGroupID();

		void printOKMessage();

        string getGroupName() { return group_name; }

    /*
     * Shutdown program
     */
    void quit();
  private:

    GUI* gui;

    int state;
    int group_id;
    string group_name;

    unsigned char ans_ch;
    string ans_str;

    void write(int value);

    client_server::Connection* conn;

    void errorOutput(unsigned char);

  };
}
#endif
